package com.borderbears.frontend.util
{
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.ui.Mouse;
	
	public class Cursor
	{
		private static var instance:Cursor;
		
		[Embed(source="assets/cursor_normal.png")]
		private static var cursor_normal:Class;
		public static var NORMAL:Bitmap = new cursor_normal();
		
		[Embed(source="assets/cursor_forward.png")]
		private static var cursor_forward:Class;
		public static var FORWARD:Bitmap = new cursor_forward();
		
		[Embed(source="assets/cursor_back.png")]
		private static var cursor_back:Class;
		public static var BACK:Bitmap = new cursor_back();
		
		private var sprite:Sprite;
		private var cursor:Sprite;
		
		
		
		public function Cursor()
		{
		}
		
		public function setCursor(b:Bitmap):void {
			Mouse.hide();
			while (cursor.numChildren > 0) {
				cursor.removeChildAt(0);
			}
			cursor.addChild(b);
		}
		
		public function restoreCursor():void {
			while (cursor.numChildren > 0) {
				cursor.removeChildAt(0);
			}
			Mouse.show();
		}
		
		public function setup():DisplayObject {
			sprite = new Sprite();
			cursor = new Sprite();
			sprite.addChild(cursor);
			sprite.addEventListener(Event.ENTER_FRAME, function(e:Event):void {
				cursor.x = sprite.mouseX;
				cursor.y = sprite.mouseY;
			});
			setCursor(NORMAL);
			return sprite;
		}
	
		public static function getCursor():Cursor {
			if (null == instance) {
				instance = new Cursor();
			}
			return instance;
		}
	}
}